/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CAKE1.java
 *
 * Created on Oct 9, 2010, 9:48:20 AM
 */

package cat200;

import java.sql.*;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import javax.swing.SpinnerNumberModel;

/**
 *
 * @author alex
 */
public class CAKE1 extends javax.swing.JFrame {

    private String url = "jdbc:derby://localhost:1527/sample";
    private String userID = "app";
    private String userPW = "app";
    private Connection con;
    private Statement stmt;
    private ResultSet rset;
    DecimalFormat dp = new DecimalFormat("#0.00");

    Object code_sale;

    String [] data1;//name
    int [] [] data2;//unit,code
    double [] [] data3;//weight,price,l_price

    SpinnerNumberModel model = new SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(1), null, Integer.valueOf(1));


    DefaultTableModel table = new DefaultTableModel
    (
        new Object [][] {},
        new String []
        {
         "Cake Code","Cake Name","Cake Flavour" ,"Cake Price"
        }
    );

    DefaultTableModel table2 = new DefaultTableModel
    (
        new Object [][] {},
        new String []
        {
         "Code","Weight","Unit" ,"TotalPrice"
        }
    );

    String temp;
    /** Creates new form CAKE1 */
    public CAKE1(String name) {
    	super("Cake menu");
        initComponents();
        connectDatabase();
        setLocationRelativeTo(null);
        if(name == null ? "CUP CAKE" == null : name.equals("CUP CAKE"))
        jComboBox1.setEnabled(false);
        jPanel7.setVisible(false);
        DisplayCake(name);
        DisplayCake2();
        System.out.println("CAKE : "+name);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, name, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 3, 14), new java.awt.Color(44, 42, 225)));

        if(name.equals("CUP CAKE"))
            jLabel6.setEnabled(false);
        else if(name.equals("FRUIT CAKE"))
                jLabel7.setEnabled(false);
        else if(name.equals("CHEESE CAKE"))
                jLabel8.setEnabled(false);
        else if(name.equals("CHOCOLATE CAKE"))
                jLabel9.setEnabled(false);
        else if(name.equals("ICE CREAM CAKE"))
                jLabel5.setEnabled(false);
        else
            System.out.println("ERROR");

        try{
            int sales;
            rset= getResultSet("SELECT SALES_NUM FROM APP.SALES WHERE SALES_NUM >= ALL (SELECT SALES_NUM FROM SALES)");
            System.out.println(rset);

            while(rset.next())
            {
                sales = rset.getInt(1);
                sales = sales +1;
                jLabel10.setText(sales+"");
            }
        }
        catch(Exception e){
            System.out.println(e);
        }
        //Java code to count the data in database and  rebuild plus add data to the table//
    }

    private void connectDatabase()
    {
        try
        {
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            con=DriverManager.getConnection(url, userID, userPW);
        }


        catch (ClassNotFoundException ex)
        {
            Logger.getLogger(CAKE1.class.getName()).log(Level.SEVERE, null, ex);
        }        catch (SQLException ex)
        {
            Logger.getLogger(CAKE1.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private ResultSet getResultSet(String doubt)
    {
        //connectDatabase();
        ResultSet outcome = null;
        try
        {
            stmt = con.createStatement();
            outcome = stmt.executeQuery(doubt);
        }
        catch (SQLException ex)
        {
            Logger.getLogger(CAKE1.class.getName()).log(Level.SEVERE, null, ex);
        }
        return outcome;
    }

    private void DisplayCake(String TYPE)
      {
        try
        {
            int col1;
            String col2,col3;
            double col4;
            //connectDatabase();

            rset= getResultSet("SELECT CAKE_CODE,CAKE_NAME,CAKE_FLAVOR,CAKE_PRICE FROM APP.CAKE WHERE CAKE_DESCRIP = '"+TYPE+"' ORDER BY CAKE_CODE");
            System.out.println(rset);

            String price = "";
            int i = 0;
            while(rset.next())
            {
                col1 = rset.getInt(1);
                col2 = rset.getString(2);
                col3 = rset.getString(3);
                col4 = rset.getDouble(4);
                
                price = dp.format(col4);
            	//col4 = Double.parseDouble(price);
                table.insertRow(i, new Object[]{col1,col2,col3,price});
                i++;
            }
            //con.close();
        }
        catch(Exception e)
        {
            System.out.println("ERROR : " + e.getMessage());
        }

//        table = new DefaultTableModel
//        (
//            new Object [][] {},
//            new String []
//            {
//            "Cake Code","Cake Name","Cake Flavour" ,"Cake Price"
//            }
//        );
        System.out.println("ROW ->"+jTable1.getRowCount());
    }

    private void DisplayCake2()
      {
        try
        {
            int col1,col3;
            double col2,col4;
            double total_price=0;
            int total_unit=0;

            rset= getResultSet("SELECT * FROM APP.TEMP ORDER BY TEMP_CODE");
            System.out.println(rset);

            int i = 0;
            String price;
            while(rset.next())
            {
                col1 = rset.getInt(1);
                col2 = rset.getDouble(4);
                col3 = rset.getInt(3);
                col4 = rset.getDouble(6);
                price = dp.format(col4);
                table2.insertRow(i, new Object[]{col1,col2,col3,price});
                total_unit +=col3;
                total_price +=col4;
                i++;
            }
            jLabel11.setText(total_unit+"");
            //jLabel12.setText(total_price+"");
            String Amt = dp.format(total_price);
            jLabel12.setText(Amt);
        }
        catch(Exception e)
        {
            System.out.println("ERROR : " + e.getMessage());
        }

//        table2 = new DefaultTableModel
//        (
//            new Object [][] {},
//            new String []
//            {
//            "Cake Code","Cake Name","Cake Flavour" ,"Cake Price"
//            }
//        );
        System.out.println("ROW ->"+jTable2.getRowCount());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jButton3 = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton4 = new javax.swing.JButton();
        jPanel6 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jSpinner1 = new javax.swing.JSpinner();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(600, 400));
        setResizable(false);

        jPanel1.setMinimumSize(new java.awt.Dimension(600, 400));
        jPanel1.setPreferredSize(new java.awt.Dimension(600, 400));
        jPanel1.setLayout(null);
        
        jLabel13.setText("Please click on the cake in the table to purchase it.");
        jPanel1.add(jLabel13);
        jLabel13.setBounds(10, 50, 410, 15);
        
        jLabel16.setText("Please select the cake to be delete.");
        jPanel1.add(jLabel16);
        jLabel16.setBounds(430, 40, 260, 15);

        jLabel1.setFont(new java.awt.Font("Times New Roman", 3, 24));
        jLabel1.setForeground(new java.awt.Color(241, 25, 198));
        jLabel1.setText("JANICE'S CAKE MENU");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(40, 20, 290, 20);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "ORDER", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 3, 14), new java.awt.Color(44, 42, 225))); // NOI18N
        jPanel2.setLayout(null);

        jLabel2.setFont(new java.awt.Font("Times New Roman", 0, 12));
        jLabel2.setText("SALE CODE:");
        jPanel2.add(jLabel2);
        jLabel2.setBounds(30, 20, 80, 20);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "CAKE", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 12))); // NOI18N
        jPanel4.setPreferredSize(new java.awt.Dimension(150, 170));

        jTable2.setModel(table2);
        jTable2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTable2MousePressed(evt);
            }
        });
        jScrollPane2.setViewportView(jTable2);

        jButton3.setText("DELETE");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(49, Short.MAX_VALUE)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(42, 42, 42))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3))
        );

        jPanel2.add(jPanel4);
        jPanel4.setBounds(10, 50, 240, 220);

        jPanel5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel5.setLayout(null);

        jLabel3.setText("TOTAL UNIT   :");
        jPanel5.add(jLabel3);
        jLabel3.setBounds(13, 15, 100, 15);

        jLabel4.setText("TOTAL PRICE :    RM");
        jPanel5.add(jLabel4);
        jLabel4.setBounds(13, 45, 150, 15);

        jLabel11.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel5.add(jLabel11);
        jLabel11.setBounds(160, 15, 70, 20);

        jLabel12.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel5.add(jLabel12);
        jLabel12.setBounds(160, 45, 70, 20);

        jPanel2.add(jPanel5);
        jPanel5.setBounds(10, 280, 240, 80);

        jButton1.setText("CLEAR");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton1);
        jButton1.setBounds(50, 390, 80, 27);

        jButton2.setText("PAID");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton2);
        jButton2.setBounds(140, 390, 80, 27);

        jLabel10.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jPanel2.add(jLabel10);
        jLabel10.setBounds(110, 20, 110, 20);

        jPanel1.add(jPanel2);
        jPanel2.setBounds(430, 60, 260, 430);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 3, 14), new java.awt.Color(44, 42, 225))); // NOI18N
        jPanel3.setLayout(null);

        jTable1.setModel(table);
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jPanel3.add(jScrollPane1);
        jScrollPane1.setBounds(10, 20, 390, 190);

        jButton4.setText("BACK");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton4);
        jButton4.setBounds(10, 380, 90, 27);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "PAGE", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 3, 12), new java.awt.Color(44, 42, 225))); // NOI18N
        jPanel6.setLayout(null);

        jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 10));
        jLabel5.setText("PAGE 5");
        jLabel5.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jLabel5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel5MouseClicked(evt);
            }
        });
        jPanel6.add(jLabel5);
        jLabel5.setBounds(220, 20, 46, 20);

        jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 10));
        jLabel6.setText("PAGE 1");
        jLabel6.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jLabel6.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel6MouseClicked(evt);
            }
        });
        jPanel6.add(jLabel6);
        jLabel6.setBounds(20, 20, 46, 20);

        jLabel7.setFont(new java.awt.Font("Times New Roman", 1, 10));
        jLabel7.setText("PAGE 2");
        jLabel7.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jLabel7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel7MouseClicked(evt);
            }
        });
        jPanel6.add(jLabel7);
        jLabel7.setBounds(70, 20, 46, 20);

        jLabel8.setFont(new java.awt.Font("Times New Roman", 1, 10));
        jLabel8.setText("PAGE 3");
        jLabel8.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jLabel8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel8MouseClicked(evt);
            }
        });
        jPanel6.add(jLabel8);
        jLabel8.setBounds(120, 20, 46, 20);

        jLabel9.setFont(new java.awt.Font("Times New Roman", 1, 10));
        jLabel9.setText("PAGE 4");
        jLabel9.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jLabel9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel9MouseClicked(evt);
            }
        });
        jPanel6.add(jLabel9);
        jLabel9.setBounds(170, 20, 46, 20);

        jPanel3.add(jPanel6);
        jPanel6.setBounds(110, 360, 290, 50);

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Cake's Sale", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 14))); // NOI18N
        jPanel7.setLayout(null);

        jLabel14.setText("Total Weight : ");
        jPanel7.add(jLabel14);
        jLabel14.setBounds(40, 20, 130, 20);

        jLabel15.setText("Total Unit : ");
        jPanel7.add(jLabel15);
        jLabel15.setBounds(40, 50, 130, 20);

        jComboBox1.setFont(new java.awt.Font("DejaVu Sans Condensed", 0, 13)); // NOI18N
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0.5 Kg", "1.0 Kg", "1.5 Kg", "2.0 Kg" }));
        jComboBox1.setSelectedIndex(1);
        jPanel7.add(jComboBox1);
        jComboBox1.setBounds(170, 20, 90, 25);

        jSpinner1.setFont(new java.awt.Font("Tw Cen MT Condensed", 0, 15));
        jSpinner1.setModel(model);
        jPanel7.add(jSpinner1);
        jSpinner1.setBounds(170, 50, 90, 26);

        jButton5.setText("Confirm");
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButton5MouseReleased(evt);
            }
        });
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jPanel7.add(jButton5);
        jButton5.setBounds(160, 90, 100, 27);

        jButton6.setText("Cancel");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel7.add(jButton6);
        jButton6.setBounds(50, 90, 100, 27);

        jPanel3.add(jPanel7);
        jPanel7.setBounds(50, 220, 310, 130);

        jPanel1.add(jPanel3);
        jPanel3.setBounds(10, 70, 410, 420);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 700, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>                        

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        this.setVisible(false);
        new Main(Main.col1).setVisible(true);
    }                                        

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        System.out.println("OK");
        
        int row = jTable1.getSelectedRow();
        System.out.println("ROW : "+row);
        String name = jTable1.getValueAt(row, 1).toString();
        code_sale = jTable1.getValueAt(row, 0).toString();


        jPanel7.setVisible(true);
        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), name, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 14))); // NOI18N


//        this.setVisible(false);
//        new CAKE2(temp,row).setVisible(true);

        //call the cake detail of row "row//"

//        jTable1 = new javax.swing.JTable();
//
//jTable1.setModel(new javax.swing.table.DefaultTableModel(
//    new Object [][] {
//        {null, null, null, null}
//    },
//    new String [] {
//        "CODE", "NAME", "FLAVOUR", "PRICE PER KG"
//    }
//) {
//    Class[] types = new Class [] {
//        java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class
//    };
//    boolean[] canEdit = new boolean [] {
//        false, false, false, false
//    };
//
//    public Class getColumnClass(int columnIndex) {
//        return types [columnIndex];
//    }
//
//    public boolean isCellEditable(int rowIndex, int columnIndex) {
//        return canEdit [columnIndex];
//    }
//});
    }                                    

    private void jLabel6MouseClicked(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        this.setVisible(false);
        new CAKE1("CUP CAKE").setVisible(true);
    }                                    

    private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        this.setVisible(false);
        new CAKE1("FRUIT CAKE").setVisible(true);
    }                                    

    private void jLabel8MouseClicked(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        this.setVisible(false);
        new CAKE1("CHEESE CAKE").setVisible(true);
    }                                    

    private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        this.setVisible(false);
        new CAKE1("CHOCOLATE CAKE").setVisible(true);
    }                                    

    private void jLabel5MouseClicked(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        this.setVisible(false);
        new CAKE1("ICE CREAM CAKE").setVisible(true);
    }                                    

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
       this.setVisible(false);
        new cashPayment().setVisible(true); // TODO add your handling code here:
    }                                        

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        double weight=0;
        int col1=0;
        String col2="";
        double col3=0;

        int temp = jComboBox1.getSelectedIndex();
        if(temp==0){weight=0.5;}
        if(temp==1){weight=1;}
        if(temp==2){weight=1.5;}
        if(temp==3){weight=2;}
        System.out.println(weight);

        int unit = model.getNumber().intValue();
        System.out.println(unit);

        try
        {
//            connectDatabase();

            rset= getResultSet("SELECT CAKE_CODE,CAKE_NAME,CAKE_PRICE FROM APP.CAKE WHERE CAKE_CODE = "+code_sale);

            while(rset.next())
            {
                col1 = rset.getInt(1);
                col2 = rset.getString(2);
                col3 = rset.getDouble(3);
                System.out.println(col1+" "+col2+" "+col3);
            }
//            con.close();
            Double cPrice = col3*unit*weight;
            String amt = dp.format(cPrice);
            Double amount = Double.parseDouble(String.valueOf(amt));
            
            String sql = "INSERT INTO TEMP VALUES ("+col1+",'"+col2+"',"+unit+","+weight+","+col3+","+amount+")";
            stmt.execute(sql);
        }
        catch(Exception e)
        {
            System.out.println("ERROR : " + e.getMessage());
            JOptionPane.showMessageDialog(null, "Item already exist in your order lists.");
        }

        jPanel7.setVisible(false);
    }                                        

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        jPanel7.setVisible(false);
    }                                        

    private void jButton5MouseReleased(java.awt.event.MouseEvent evt) {                                       
        // TODO add your handling code here:

//        table.setRowCount( table.getRowCount() + 1 );
//	int row = table.getRowCount() - 1;
//	jTable1.changeSelection(row, 0, false, false);
//	jTable1.requestFocusInWindow();
        int numRows = table2.getRowCount();
       for(int i=numRows-1;i>=0;i--)
        {
            table2.removeRow(i);
        }

        DisplayCake2();
    }                                      

    Object delete_code = null;
    private void jTable2MousePressed(java.awt.event.MouseEvent evt) {                                     
        // TODO add your handling code here:
        delete_code = jTable2.getValueAt(jTable2 .getSelectedRow(), 0);
        System.out.println("DELETE_CODE = "+delete_code);
    }                                    

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        try{
        String sql = "DELETE FROM TEMP";
        stmt.execute(sql);

        int numRows = table2.getRowCount();
        for(int i=numRows-1;i>=0;i--)
        {
            table2.removeRow(i);
        }
         
        }catch(Exception e){
        System.out.println(e);
        }
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:

        if(delete_code == null)
            JOptionPane.showMessageDialog(null, "Nothing to be delete!");
        else{
        try{
        String sql = "DELETE FROM TEMP WHERE TEMP_CODE = "+delete_code;
        stmt.execute(sql);

        int numRows = table2.getRowCount();
        for(int i=numRows-1;i>=0;i--)
        {
            table2.removeRow(i);
        }

        delete_code = null;
        DisplayCake2();
        }catch(Exception e){
        System.out.println(e);
        }
        }
    }                                        

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CAKE1("").setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSpinner jSpinner1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel16;
    // End of variables declaration                   

}
